using System.Collections;
using I2.Loc;
using UnityEngine;

public class DeathMessage : MonoBehaviour
{
	[SerializeField]
	private UITweener[] deathAnimationShow;

	[SerializeField]
	private UITweener[] deathAnimationHide;

	[SerializeField]
	private UILabel text;

	public bool showTimeForRespawn = true;

	[SerializeField]
	private UITweener deathBackground;

	private bool lastShow;

	private void OnEnable()
	{
		if (text != null)
		{
			text.gameObject.SetActive(false);
		}
		if (GameController.instance.curTypeGame == TypeGame.CopsAndRobbers)
		{
			showTimeForRespawn = true;
		}
		else
		{
			showTimeForRespawn = false;
		}
	}

	public void Show()
	{
		if (!base.gameObject.GetActive())
		{
			base.gameObject.SetActive(true);
		}
		if (!base.gameObject.GetActive())
		{
			return;
		}
		BCWDebug.Log("&&&&&&&&&&&&&&& Show Dead");
		lastShow = true;
		for (int i = 0; i < deathAnimationShow.Length; i++)
		{
			deathAnimationShow[i].ResetToBeginning();
			deathAnimationShow[i].PlayForward();
			if (showTimeForRespawn)
			{
				StartCoroutine(ShowResetTime(PlayerBehavior.MyPlayer.GetTimeForRespawn()));
			}
		}
	}

	public void Hide()
	{
		if (base.gameObject.GetActive())
		{
			base.gameObject.SetActive(false);
		}
		else if (lastShow)
		{
			BCWDebug.Log("&&&&&&&&&&&&&&&&  Hide Dead");
			lastShow = false;
			for (int i = 0; i < deathAnimationHide.Length; i++)
			{
				deathAnimationHide[i].ResetToBeginning();
				deathAnimationHide[i].PlayForward();
			}
		}
		ChangeDurationBackground(10f);
	}

	public void ChangeDurationBackground(float duration)
	{
		deathBackground.duration = duration;
	}

	private IEnumerator ShowResetTime(float time)
	{
		if (!(text == null))
		{
			text.text = string.Empty;
			text.gameObject.SetActive(true);
			int newTime = Mathf.FloorToInt(time);
			while (newTime >= 0)
			{
				text.text = string.Format(ScriptLocalization.Get("Game_Common/sm_CopsAndRobbers_ressurect"), newTime);
				newTime--;
				yield return new WaitForSeconds(1f);
			}
			yield return null;
		}
	}
}
